window.addEvent('domready', function() {
	//
    // Set up our dynamic navigation menu
    //
    

	
    var menus = $$(".navMenuBody");
    
    menus.each(function (m) {
        title = $(m.id + 'Div');
        
        //
        // Only create a nav menu if the element has a corresponding
        // title element
        //
        
        if(title)
        {
            title.myMenu = new Fx.Slide(m);
            title.myMenu.hide();
            
            title.addEvent('mouseenter', function(e) {
            	ev = new Event(e);
                
                this.myMenu.isClosing = false;
                this.myMenu.slideIn();
                
                ev.stop();
            });
            
            var closeMenus = function() {
            	$$('.navMenu').each(function (t) {
             		if(t.myMenu.isClosing)
                    	t.myMenu.slideOut();
                });   
            };
            
            title.addEvent('mouseleave', function(e) {
	            var ev = new Event(e);
                this.myMenu.isClosing = true;
            	closeMenus.delay(4000);
                ev.stop();
            });
        };
    });
	
	
	
	// animated guild anchor tags
	var navs = $$('div.navMenu a', 'div.navMenu .navMenuTitle');
	
	var active = {
			'color'				: 'FFFFFF',
			'border-left-color'	: '6C2424',
			'background-color'	: '131313',
			'text-indent'	  	: '7px'
		};
	var sleepy = {
			'color'				: 'AAAAAA',
			'background-color'	: '0A0A0A',
			'border-left-color' : '472323'
		};
	var asleep = {
			'border-left-color'	: '131313',
			'background-color'	: '000000',
			'text-indent'		: '0px'
		};
	
	navs.each(function(element, i) {
		var fx = new Fx.Styles(element, {duration:300, wait:false});
	 
		element.addEvent('mouseenter', function(){
			fx.start(active);
		});
	 
		// two phase fade
		element.addEvent('mouseleave', function(){
			fx.start(sleepy).chain(function() {
					fx.start.delay(150, fx, asleep);
				});
		});
	});
	
	
	/*  second level navigation items : slide-outs.
		how it works: knobs toggle drawers
	*/
	var drawers = $$('ul.navigation li ul');
	drawers.each(function(drawer) {
		var knob = drawer.getParent();
		var slideDrawer = new Fx.Slide(drawer);
		slideDrawer.hide();
		
		knob.addEvent('click', function() {
			slideDrawer.toggle();
		});
	});
});
